from bs4 import BeautifulSoup
import requests


head = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
}

# 需要获取所有页面的数据
for start_num in range(0, 250, 25):
    # 获取源码
    content = requests.get(f"https://movie.douban.com/top250?start={start_num}&filter=", headers= head).text
    soup = BeautifulSoup(content, "html.parser")

    # 查找元素
    movie_names = soup.findAll("span", attrs= {"class" : "title"})

    # 输出电影名数据
    for movie_name in movie_names:
        name = movie_name.string
        if "/" not in name:
            print("电影名: ", name)
